package dataSet;

import java.util.*;

public class MembershipMatrix {

	private Map<Nop, Map<Nop, Membership>> membershipMatrix;

	public MembershipMatrix() {
		this.membershipMatrix = new HashMap<Nop, Map<Nop, Membership>>();
	}

	public MembershipMatrix(Nop aNop, List<Membership> membershipOfNop) {
		this.membershipMatrix = new HashMap<Nop, Map<Nop, Membership>>();
		this.membershipMatrix.put(aNop, new HashMap<Nop, Membership>());
		for (Membership aMembership : membershipOfNop) {
			this.membershipMatrix.get(aNop).put(aMembership.getNop(), aMembership);
		}
	}

	public Membership getMembership(Nop aNop, Nop aCenter) {
		if (this.membershipMatrix.containsKey(aNop)) {
			return this.membershipMatrix.get(aNop).get(aCenter);
		} else
			return null;
	}

	public Map<Nop, Membership> getMembershipOfNop(Nop aNop) {
		if (this.membershipMatrix.containsKey(aNop)) {
			return this.membershipMatrix.get(aNop);
		} else
			return null;
	}

	public Double getMembershipValue(Nop aNop, Nop aCenter) {
		if (this.membershipMatrix.containsKey(aNop)) {
			return this.membershipMatrix.get(aNop).get(aCenter).getMembershipValue();
		}
		return 0d;
	}

	public void setMembershipWithMembershipsOfNop(Nop aNop, List<Membership> membershipOfNop) {

		Map<Nop, Membership> membershipsOfNopMap = new HashMap<Nop, Membership>();
		for (Membership aMembership : membershipOfNop) {
			Nop center = aMembership.getCenter();
			membershipsOfNopMap.put(center, aMembership);
			this.membershipMatrix.put(aNop, membershipsOfNopMap);
		}
	}

	public void removeMembership() {
		// not finished yet

	}

	public void showMembershipMatrix() {
		Set<Nop> nopList = this.membershipMatrix.keySet();

		for (Nop aNop : nopList) {
			Set<Nop> centersList = this.membershipMatrix.get(aNop).keySet();
			System.out.print("Nop " + aNop + "\t");
			for (Nop aCenter : centersList) {
				System.out.printf("%4.4f\t", this.membershipMatrix.get(aNop).get(aCenter).getMembershipValue());
			}
			System.out.println();
		}
	}
}
